package cn.edu.xhu.library_management.book.controller;

import cn.edu.xhu.library_management.book.entity.LmBookCategory;
import cn.edu.xhu.library_management.book.service.LmBookCategoryService;
import cn.edu.xhu.library_management.common.entity.R;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2023 - 03 - 15
 * @Description: 图书分类控制器
 */
@Api(tags = "图书分类")
@ApiSort(1)
@RestController
@RequestMapping("/lm_book")
public class BookCategoryController {

    @Autowired
    private LmBookCategoryService bookCategoryService;

    @ApiOperation(value = "通过父类查询子类", produces = "application/json")
    @ApiOperationSupport(order = 111)
    @GetMapping("/category/{pid}")
    public R findCategoryByPid(@PathVariable(name = "pid") Long pid) {
        return R.ok().data("categories",bookCategoryService.findCategoryByPId(pid));
    }

    @ApiOperation(value = "通过code或者名称搜索", produces = "application/json")
    @ApiOperationSupport(order = 111)
    @GetMapping("/category")
    public R searchCategoryByCodeOrName(@Param("type") Integer type,@Param("content") String content){
        List<LmBookCategory> categories =bookCategoryService.searchCategoryByCodeOrName(type,content);
        return R.ok().data("categories",categories);
    }


}
